package com.xxcxcxcx.jobsystem.common.Job;

import com.xxcxcxcx.jobsystem.Main;
import com.xxcxcxcx.jobsystem.PlayerSaveData;
import com.xxcxcxcx.jobsystem.common.Job.Blacksmith.Blacksmith;
import com.xxcxcxcx.jobsystem.common.Job.Brewmaster.Brewmaster;
import com.xxcxcxcx.jobsystem.common.Job.Cook.Cook;
import com.xxcxcxcx.jobsystem.common.Job.Cook.ModifyCraftResultEvent;
import com.xxcxcxcx.jobsystem.common.Job.Enchanter.Enchanter;
import com.xxcxcxcx.jobsystem.common.Job.Endurance.Endurance;
import com.xxcxcxcx.jobsystem.common.Job.Farmer.Farmer;
import com.xxcxcxcx.jobsystem.common.Job.Herdsman.Herdsman;
import com.xxcxcxcx.jobsystem.common.Job.Lumberman.Lumberman;
import com.xxcxcxcx.jobsystem.common.Job.MeleeAttack.MeleeAttack;
import com.xxcxcxcx.jobsystem.common.Job.Miner.Miner;
import com.xxcxcxcx.jobsystem.common.Job.RemoteAttack.RemoteAttack;
import com.xxcxcxcx.jobsystem.common.JobsClass;
import com.xxcxcxcx.jobsystem.common.capability.JobCapability;
import com.xxcxcxcx.jobsystem.common.capability.JobCapabilityProvider;
import com.xxcxcxcx.jobsystem.mixin.job.Herdsman.EntityDrop;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.damagesource.EntityDamageSource;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.AgeableMob;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.OwnableEntity;
import net.minecraft.world.entity.TamableAnimal;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.PotionItem;
import net.minecraft.world.item.TieredItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.event.enchanting.EnchantmentLevelSetEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.BabyEntitySpawnEvent;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.living.PotionEvent;
import net.minecraftforge.event.entity.player.BonemealEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.List;
import java.util.Objects;
import java.util.UUID;

import static com.xxcxcxcx.jobsystem.common.Job.Blacksmith.Blacksmith.*;
import static com.xxcxcxcx.jobsystem.common.Job.Brewmaster.Brewmaster.*;
import static com.xxcxcxcx.jobsystem.common.Job.Cook.Cook.*;
import static com.xxcxcxcx.jobsystem.common.Job.Enchanter.Enchanter.enchanter;
import static net.minecraftforge.eventbus.api.Event.Result.DENY;

@Mod.EventBusSubscriber
public class JobEevnt {
    //骨粉催熟时候农夫有概率加倍
    @SubscribeEvent(priority = EventPriority.LOWEST)
    public static void onBoneMeal(BonemealEvent event) {
        if(event.getWorld() instanceof ServerLevel serverWorld){
            int count = Farmer.getBonemealCount(event.getPlayer(),event.getBlock(),event.getWorld(),event.getPos());
            if(count == 0) {
                event.setResult(Event.Result.ALLOW);
            } else if(count > 0 && event.getBlock().getBlock() instanceof BonemealableBlock fertilizable && fertilizable.isValidBonemealTarget(event.getWorld(), event.getPos(), event.getBlock(), false)) {
                event.setResult(Event.Result.ALLOW);
                Level world = event.getWorld();
                BlockPos pos = event.getPos();
                BlockState state = event.getBlock();
                if(fertilizable.isValidBonemealTarget(world, pos, state, false)) {
                    for(int i = 0; i < count; i++) {
                        if(fertilizable.isBonemealSuccess(world, world.random, pos, state)) {
                            fertilizable.performBonemeal(serverWorld, world.random, pos, state);
                        }
                    }
                }
            }
        }
    }
    //农夫踩不坏耕地
    @SubscribeEvent
    public static void FarmlandTRampleChange(BlockEvent.FarmlandTrampleEvent event) {
        if(event.getWorld() instanceof ServerLevel serverWorld){
            if(Farmer.Farmland(event.getEntity())){
                event.setCanceled(true);
            }
        }
    }
    //矿工挖掘速度改变,伐木工砍树速度改变
    @SubscribeEvent(priority = EventPriority.HIGHEST)
    public static void onBreakSpeed(PlayerEvent.BreakSpeed event) {
        if(event.getState().getBlock() == Blocks.SPAWNER)event.setCanceled(true);
        if(Miner.GetRightBlock(event.getState())){
            event.setNewSpeed(Miner.GetMineSpeed(event.getPlayer(),event.getState(),event.getOriginalSpeed()));
        }
        if(Lumberman.GetRightBlock(event.getState())){
            event.setNewSpeed(Lumberman.GetMineSpeed(event.getPlayer(),event.getState(),event.getOriginalSpeed()));
        }
    }
    //矿工挖矿可以额外掉落,伐木掉落提升
    @SubscribeEvent(priority = EventPriority.HIGHEST)
    public static void BreakBlock(BlockEvent.BreakEvent event) {
        if(event.getWorld() instanceof ServerLevel serverWorld){
            if(Miner.GetRightBlock(event.getState()))Miner.GetBreak(event.getState(),event.getPlayer());
            if(Lumberman.GetRightBlock(event.getState()))Lumberman.DropMore(event.getState(),event.getPlayer());
        }
    }
    //挤牛奶，剪羊毛，喂动物，级别低时候会掉血
    @SubscribeEvent
    public static void TouchEntity(PlayerInteractEvent.EntityInteract event) {
        if(event.getWorld() instanceof ServerLevel serverWorld && event.getHand()== InteractionHand.MAIN_HAND){
            Herdsman.TouchEntity(event.getPlayer(),event.getTarget());
        }
    }
    //击杀生物时候掉落物不同
    @SubscribeEvent
    public static void onLivingDrops(LivingDropsEvent event) {
        if(event.getSource() instanceof EntityDamageSource eds ) {
            if(eds.getEntity() instanceof Player player){
                LivingEntity target = event.getEntityLiving();
                if(Herdsman.RightMob(target)){
                    event.setCanceled(true);
                    int amount = Herdsman.GetDrop(player,target);
                    for(int i = 0; i < amount; ++i) {
                        ((EntityDrop)target).invokeDropFromLootTable(event.getSource(), true);
                    }
                }
            }else if (eds.getEntity() instanceof OwnableEntity ownableEntity && ownableEntity.getOwner() != null && ownableEntity.getOwner() instanceof Player player){
                LivingEntity target = event.getEntityLiving();
                if(Herdsman.RightMob(target)){
                    event.setCanceled(true);
                    int amount = Herdsman.GetDrop(player,target);
                    for(int i = 0; i < amount; ++i) {
                        ((EntityDrop)target).invokeDropFromLootTable(event.getSource(), true);
                    }
                }
            }
        }
    }
    //多胞胎
    @SubscribeEvent(priority = EventPriority.LOWEST)
    public static void onBabyEntitySpawn(BabyEntitySpawnEvent event) {
        AgeableMob child = event.getChild();
        if(child != null && event.getParentA() instanceof Animal a &&event.getParentB() instanceof Animal b ){
            Player playera=a.getLoveCause();
            Player playerb=b.getLoveCause();
            if(playera!=null&&Objects.equals(playera,playerb)){
                int num = Herdsman.MoreBaby(playera);
                boolean flag=(a instanceof OwnableEntity ownableEntitya && b instanceof OwnableEntity ownableEntityb &&
                        ownableEntitya.getOwner() != null && Objects.equals(ownableEntitya.getOwnerUUID(), ownableEntityb.getOwnerUUID()));
                if(flag){
                    if(child instanceof TamableAnimal c&&a instanceof OwnableEntity ownableEntitya){
                        c.setOwnerUUID(ownableEntitya.getOwnerUUID());
                    }
                    event.setChild(child);
                }
                for (int i=0;i<num;i++){
                    AgeableMob ageablemob = a.getBreedOffspring((ServerLevel) playera.level, b);
                    if (ageablemob != null) {
                        if(flag && ageablemob instanceof TamableAnimal c&&a instanceof OwnableEntity ownableEntitya){
                            c.setOwnerUUID(ownableEntitya.getOwnerUUID());
                        }
                        ageablemob.setBaby(true);
                        ageablemob.moveTo(a.getX(), a.getY(), a.getZ(), 0.0F, 0.0F);
                        ((ServerLevel)(playera.level)).addFreshEntityWithPassengers(ageablemob);
                    }
                }
            }
        }
    }
    //生物继承药水
    @SubscribeEvent(priority = EventPriority.LOWEST)
    public static void onPotionGained(PotionEvent.PotionAddedEvent event) {
        MobEffectInstance effect = event.getPotionEffect();
        LivingEntity entity = event.getEntityLiving();
        if(effect.getEffect().isBeneficial() && entity instanceof Player player) {
            LazyOptional<JobCapability> capability = JobCapabilityProvider.getPlayerData(player);
            if(!capability.isPresent()) {
                return;
            }
            PlayerSaveData playerSaveData = capability.orElse(null);
            int JobLevel = playerSaveData.getLevel(JobsClass.Herdsman);
            if(JobLevel>=7){
                float L = (JobLevel-3)*1.5f+4.0f;
                entity.level.getEntitiesOfClass(LivingEntity.class,
                        entity.getBoundingBox().expandTowards(L, L/4, L).expandTowards(-L, -L/4, -L),
                        e -> e instanceof OwnableEntity ownable && Objects.equals(ownable.getOwnerUUID(), player.getUUID())
                ).forEach(e -> e.addEffect(effect, event.getPotionSource() == null ? entity : event.getPotionSource()));
            }
        }
    }
    //生物代替承受负面药水
    @SubscribeEvent
    public static void GetPotionGained(PotionEvent.PotionApplicableEvent event) {
        MobEffectInstance effect = event.getPotionEffect();
        LivingEntity entity = event.getEntityLiving();
        if(!effect.getEffect().isBeneficial() && entity instanceof Player player) {
            LazyOptional<JobCapability> capability = JobCapabilityProvider.getPlayerData(player);
            if(!capability.isPresent()) {
                return;
            }
            PlayerSaveData playerSaveData = capability.orElse(null);
            int JobLevel = playerSaveData.getLevel(JobsClass.Herdsman);
            if(JobLevel==10){
                float L = 15f;
                List<LivingEntity> entities= entity.level.getEntitiesOfClass(LivingEntity.class,
                        entity.getBoundingBox().expandTowards(L, L/4, L).expandTowards(-L, -L/4, -L),
                        e -> e instanceof OwnableEntity ownable && Objects.equals(ownable.getOwnerUUID(), player.getUUID())
                );
                LivingEntity livingEntity = entities.get(player.getRandom().nextInt(entities.size()));
                while(livingEntity.hasEffect(effect.getEffect())){
                    entities.remove(livingEntity);
                    if(entities.isEmpty())break;
                    livingEntity = entities.get(player.getRandom().nextInt(entities.size()));
                }
                if(!entities.isEmpty()){
                    livingEntity.addEffect(effect, player);
                    event.setResult(DENY);
                }
            }
        }
    }
    //伐木工获得树苗
    @SubscribeEvent
    public static void GetWood(PlayerInteractEvent.RightClickBlock event){
        if(event.getPlayer() instanceof ServerPlayer serverPlayer){
            Lumberman.Get(serverPlayer,event.getPos());
        }
    }
    //厨师做饭获得特殊食物
    @SubscribeEvent
    public static void onFoodCrafted(ModifyCraftResultEvent event) {
        Player player = event.getPlayer();
        ItemStack stack = event.getCrafted();
        if(stack.getFoodProperties(player) != null) {
            Cook.GetCook(player, stack);
        }
        if(stack.getItem() instanceof ArmorItem || stack.getItem() instanceof TieredItem) {
            Blacksmith.GetTools(player, stack);
        }
    }
    //农夫右键喂食
    @SubscribeEvent
    public static void onInteractEntity(PlayerInteractEvent.EntityInteract event) {
        if(event.getPlayer() instanceof ServerPlayer sp &&event.getTarget() instanceof LivingEntity livingEntity) {
            Farmer.FarmFeedFood(sp,event.getHand(),livingEntity);
        }
    }
    //厨师右键食物（半废弃）
    @SubscribeEvent
    public static void onFoodUnIdentification(PlayerInteractEvent.RightClickItem event) {
        if(event.getHand() == InteractionHand.MAIN_HAND){
            Player player = event.getPlayer();
            ItemStack stack = player.getItemInHand(event.getHand());
            CompoundTag nbt=stack.getOrCreateTagElement(Main.MOD_ID);
            if(nbt.isEmpty()){
                stack.removeTagKey(Main.MOD_ID);
            }else{
                if(nbt.getString(MakeFood+FoodLevel).equals(UnIdentification)){
                    if(nbt.getString(MakeFood+Cooker).equals(player.getName().getContents())&&event.getPlayer() instanceof ServerPlayer){
                        Cook.IdentificationFood(player,stack);
                    }
                    event.setCanceled(true);
                }
                if(nbt.getString(MakeTool+ToolLevel).equals(ToolUnIdentification)){
                    if(nbt.getString(MakeTool+Creater).equals(player.getName().getContents())&&event.getPlayer() instanceof ServerPlayer){
                        Blacksmith.IdentificationTool(player,stack);
                    }
                    event.setCanceled(true);
                }
            }
        }
    }
    //附魔等级设定
    @SubscribeEvent(priority = EventPriority.LOWEST)
    public static void onEnchantmentLevel(EnchantmentLevelSetEvent event) {
        ItemStack itemStack = event.getItem();
        CompoundTag n=itemStack.getOrCreateTagElement(Main.MOD_ID);
        if(n.isEmpty()){
            itemStack.removeTagKey(Main.MOD_ID);
        }else{
            UUID uuid = n.getUUID(enchanter);
            Player player = event.getWorld().getPlayerByUUID(uuid);
            if(player != null) {
                event.setLevel(Enchanter.ChangeLevel(player,event.getLevel(),event.getEnchantRow()));
            }
        }
    }
    @SubscribeEvent(priority = EventPriority.LOWEST)
    public static void onAttackPlayerLevel(LivingAttackEvent event) {
        if(event.getSource().getEntity() == event.getEntity())return;
        if(event.getAmount()<1)return;
        if(event.getEntity() instanceof ServerPlayer serverPlayer){
            Endurance.UpExperienceChange(serverPlayer,event.getAmount()/3,JobsClass.Endurance);
        }
        if(event.getSource().msgId.equals("player")){
            if(event.getSource().getEntity() instanceof ServerPlayer serverPlayer){
                MeleeAttack.UpExperienceChange(serverPlayer,event.getAmount()/10,JobsClass.MeleeAttack);
            }
        }
        if(event.getSource().msgId.equals("arrow")){
            if(event.getSource().getEntity() instanceof ServerPlayer serverPlayer){
                RemoteAttack.UpExperienceChange(serverPlayer,event.getAmount()/10,JobsClass.RemoteAttack);
            }
        }
    }
    //箭射击速度和伤害
    @SubscribeEvent
    public static void onArrowShoots(EntityJoinWorldEvent event) {
        if(event.getEntity() instanceof AbstractArrow arrow && arrow.getOwner() instanceof ServerPlayer serverPlayer) {
            arrow.setBaseDamage(arrow.getBaseDamage() * RemoteAttack.getDamage(serverPlayer));
        }
    }
    //物品提示框显示
    @SubscribeEvent
    public static void onTooltip(ItemTooltipEvent event) {
        Player player = event.getPlayer();
        if(player == null) return;
        ItemStack stack = event.getItemStack();
        List<Component> tooltip = event.getToolTip();
        CompoundTag nbt = stack.getOrCreateTagElement(Main.MOD_ID);
        if(nbt.isEmpty()){
            stack.removeTagKey(Main.MOD_ID);
            if(stack.getFoodProperties(player) != null) {
                tooltip.add(new TranslatableComponent("jobsystem.tooltip.foodlevel.uncook").withStyle(ChatFormatting.GRAY));
            }
            if(stack.getItem() instanceof ArmorItem || stack.getItem() instanceof TieredItem) {
                tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel.uncreat").withStyle(ChatFormatting.GRAY));
            }
            if(stack.getItem() instanceof PotionItem){
                tooltip.add(new TranslatableComponent("jobsystem.tooltip.potionlevel.uncreat").withStyle(ChatFormatting.GRAY));
            }
        }else{
            if(stack.getFoodProperties(player) != null) {
                String s = nbt.getString(MakeFood+FoodLevel);
                if(s.equals(UnIdentification)){
                    tooltip.add(new TranslatableComponent("jobsystem.tooltip.foodlevel.unidentification").withStyle(ChatFormatting.GRAY));
                }else if(s.equals("")){
                    tooltip.add(new TranslatableComponent("jobsystem.tooltip.foodlevel.uncook").withStyle(ChatFormatting.GRAY));
                    return;
                }else{
                    for(int i=0;i<FoodLevels.length;i++){
                        if(s.equals(FoodLevels[i])){
                            if(i==0)tooltip.add(new TranslatableComponent("jobsystem.tooltip.foodlevel."+FoodLevels[i]).withStyle(ChatFormatting.WHITE));
                            else if(i==1)tooltip.add(new TranslatableComponent("jobsystem.tooltip.foodlevel."+FoodLevels[i]).withStyle(ChatFormatting.GREEN));
                            else if(i==2)tooltip.add(new TranslatableComponent("jobsystem.tooltip.foodlevel."+FoodLevels[i]).withStyle(ChatFormatting.BLUE));
                            else if(i==3)tooltip.add(new TranslatableComponent("jobsystem.tooltip.foodlevel."+FoodLevels[i]).withStyle(ChatFormatting.DARK_PURPLE));
                            else tooltip.add(new TranslatableComponent("jobsystem.tooltip.foodlevel."+FoodLevels[i]).withStyle(ChatFormatting.YELLOW));
                        }
                    }
                    int nutrition= nbt.getInt(MakeFood+Newnutrition);
                    int saturation=Math.round(nbt.getFloat(MakeFood+Newsaturation)*10);
                    if(nutrition>0)tooltip.add(new TranslatableComponent("jobsystem.tooltip.foodlevel.nutrition.up",nutrition).withStyle(ChatFormatting.BLUE));
                    else tooltip.add(new TranslatableComponent("jobsystem.tooltip.foodlevel.nutrition.down",-nutrition).withStyle(ChatFormatting.BLUE));
                    if(saturation>0)tooltip.add(new TranslatableComponent("jobsystem.tooltip.foodlevel.saturation.up",saturation).withStyle(ChatFormatting.BLUE));
                    else tooltip.add(new TranslatableComponent("jobsystem.tooltip.foodlevel.saturation.dowm",-saturation).withStyle(ChatFormatting.BLUE));
                    for(int i=1;i<=32;i++){
                        if(nbt.contains(MakeFood+Effect+ i)){
                            int time= nbt.getInt(MakeFood+Effect+ i +EffectTime);
                            int level= nbt.getInt(MakeFood+Effect+ i +EffectLevel);
                            float chance= nbt.getFloat(MakeFood+Effect+ i +EffectChance);
                            MobEffect mobEffect = MobEffect.byId(i);
                            MobEffectInstance m=new MobEffectInstance(mobEffect,time,level);
                            tooltip.add(new TranslatableComponent("jobsystem.tooltip.foodeffect",new TranslatableComponent(m.getDescriptionId())).withStyle(ChatFormatting.BLUE));
                        }
                    }
                }
                tooltip.add(new TranslatableComponent("jobsystem.tooltip.cook", nbt.getString(MakeFood+Cooker)).withStyle(ChatFormatting.GOLD));
            }
            if(stack.getItem() instanceof ArmorItem || stack.getItem() instanceof TieredItem) {
                String s = nbt.getString(MakeTool+ToolLevel);
                String s2 = nbt.getString(MakeTool+ToolKind);
                if(s.equals(ToolUnIdentification)){
                    tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel.unidentification").withStyle(ChatFormatting.GRAY));
                }else if(s.equals("")){
                    tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel.uncreat").withStyle(ChatFormatting.GRAY));
                    return;
                }else{
                    for(int i=0;i<ToolLevels.length;i++){
                        if(s.equals(ToolLevels[i])){
                            if(i==0)tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel."+ToolLevels[i]).withStyle(ChatFormatting.WHITE));
                            else if(i==1)tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel."+ToolLevels[i]).withStyle(ChatFormatting.GREEN));
                            else if(i==2)tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel."+ToolLevels[i]).withStyle(ChatFormatting.BLUE));
                            else if(i==3)tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel."+ToolLevels[i]).withStyle(ChatFormatting.DARK_PURPLE));
                            else tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel."+ToolLevels[i]).withStyle(ChatFormatting.YELLOW));
                        }
                    }
                    if(stack.getItem() instanceof ArmorItem){
                        for(int i=0;i<ToolKinds.length;i++){
                            if(s2.equals(ToolKinds[i])){
                                if(i==0)tooltip.add(new TranslatableComponent("jobsystem.tooltip.toolkind."+ToolKinds[i]).withStyle(ChatFormatting.WHITE));
                                else if(i==1)tooltip.add(new TranslatableComponent("jobsystem.tooltip.toolkind."+ToolKinds[i]).withStyle(ChatFormatting.GREEN));
                                else if(i==2)tooltip.add(new TranslatableComponent("jobsystem.tooltip.toolkind."+ToolKinds[i]).withStyle(ChatFormatting.BLUE));
                                else if(i==3)tooltip.add(new TranslatableComponent("jobsystem.tooltip.toolkind."+ToolKinds[i]).withStyle(ChatFormatting.DARK_PURPLE));
                                else tooltip.add(new TranslatableComponent("jobsystem.tooltip.toolkind."+ToolKinds[i]).withStyle(ChatFormatting.YELLOW));
                            }
                        }
                        float num=(nbt.getFloat(MakeTool+Durable)-1)*100;
                        if(num>0)tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel.durable.up",String.format("%.1f", num)).withStyle(ChatFormatting.BLUE));
                        else tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel.durable.down",String.format("%.1f", -num)).withStyle(ChatFormatting.BLUE));
                    }
                    else if(stack.getItem() instanceof TieredItem){
                        float num=(nbt.getFloat(MakeTool+Durable)-1)*100;
                        if(num>0)tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel.durable.up",String.format("%.1f", num)).withStyle(ChatFormatting.BLUE));
                        else tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel.durable.down",String.format("%.1f", -num)).withStyle(ChatFormatting.BLUE));
                        num=(nbt.getFloat(MakeTool+Speed)-1)*100;
                        if(num>0)tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel.speed.up",String.format("%.1f", num)).withStyle(ChatFormatting.BLUE));
                        else tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel.speed.down",String.format("%.1f", -num)).withStyle(ChatFormatting.BLUE));
                        num=(nbt.getFloat(MakeTool+Damage)-1)*100;
                        if(num>0)tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel.damage.up",String.format("%.1f", num)).withStyle(ChatFormatting.BLUE));
                        else tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel.damage.down",String.format("%.1f", -num)).withStyle(ChatFormatting.BLUE));
                        num=(nbt.getFloat(MakeTool+DamageSpeed)-1)*100;
                        if(num>0)tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel.damagespeed.up",String.format("%.1f", num)).withStyle(ChatFormatting.BLUE));
                        else tooltip.add(new TranslatableComponent("jobsystem.tooltip.toollevel.damagespeed.down",String.format("%.1f", -num)).withStyle(ChatFormatting.BLUE));
                    }
                }
                tooltip.add(new TranslatableComponent("jobsystem.tooltip.creat", nbt.getString(MakeTool+Creater)).withStyle(ChatFormatting.GOLD));
            }
            if(Brewmaster.hasPotionBonus(stack)) {
                int level = nbt.getInt(Refining);
                if(level==0)tooltip.add(new TranslatableComponent("jobsystem.tooltip.refiningkind."+RefiningKinds[level]).withStyle(ChatFormatting.GREEN));
                else if(level==1)tooltip.add(new TranslatableComponent("jobsystem.tooltip.refiningkind."+RefiningKinds[level]).withStyle(ChatFormatting.GREEN));
                else if(level==2)tooltip.add(new TranslatableComponent("jobsystem.tooltip.refiningkind."+RefiningKinds[level]).withStyle(ChatFormatting.DARK_PURPLE));
                else if(level==3)tooltip.add(new TranslatableComponent("jobsystem.tooltip.refiningkind."+RefiningKinds[level]).withStyle(ChatFormatting.DARK_PURPLE));
                else tooltip.add(new TranslatableComponent("jobsystem.tooltip.refiningkind."+RefiningKinds[level]).withStyle(ChatFormatting.YELLOW));
                tooltip.add(new TranslatableComponent("jobsystem.tooltip.refining", nbt.getString(Refining+RefiningCreater)).withStyle(ChatFormatting.GOLD));
            }
        }
    }
}
